﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 华容道
{
    /// <summary>
    /// 10个板块
    /// 0x0--空地--0   2个
    /// 1x1--小兵--1   4个
    /// 2x1--横將--2   ？个
    /// 1x2--竖将--3   ？个
    /// 2x2--曹操--4   1个
    /// 
    /// 横將+竖将=5个
    /// </summary>
    public class Block
    {
        public int x;
        public int y;
        public int width;
        public int height;
        /// <summary>
        /// 类型
        /// 0x0--空地--0
        /// 1x1--小兵--1
        /// 2x1--横將--2
        /// 1x2--竖将--3
        /// 2x2--曹操--4
        /// </summary>
        public int type;

        public Block(int x, int y, int width, int height,int type)
        {
            this.x = x;
            this.y = y;
            this.width = width;
            this.height = height;
            this.type = type;
        }

        public Block(Block block)
        {
            x = block.x;
            y = block.y;
            width = block.width;
            height = block.height;
            type = block.type;
        }

        public bool CanLeft(int[,] map)
        {
            if (y <= 0)
            {
                return false;
            }

            for (int i = x, j = y - 1; i < x + height; i++)
            {
                if (map[i, j] != 0)
                {
                    return false;
                }
            }

            return true;
        }

        public bool CanRight(int[,] map)
        {
            if (y + width >= 4)
            {
                return false;
            }

            for (int i = x, j = y +width; i < x + height; i++)
            {
                if (map[i, j] != 0)
                {
                    return false;
                }
            }

            return true;
        }

        public bool CanUp(int[,] map)
        {
            if (x <= 0)
            {
                return false;
            }

            for(int i = x - 1, j = y; j < y + width; j++)
            {
                if (map[i, j] != 0)
                {
                    return false;
                }
            }

            return true;
        }

        public bool CanDown(int[,] map)
        {
            if (x + height >= 5)
            {
                return false;
            }

            for(int i = x + height, j = y; j < y + width; j++)
            {
                if (map[i, j] != 0)
                {
                    return false;
                }
            }

            return true;
        }
    }
}
